package Chap03;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Random;
import java.util.Scanner;
import java.util.Set;

public class Supermarket {
    //初始化
    static Goods[] goods=new Goods[4];
    static {
        goods[0]=new Goods(1,"大连富士",3.5,20);
        goods[1]=new Goods(2,"山东富士",3.5,10);
        goods[2]=new Goods(3,"进口香蕉",3.5,30);
        goods[3]=new Goods(4,"皇妃蜜桔",3.5,40);
    }
    public static void main(String[] args) {
        System.out.println("\t欢迎光临阿钰水果店,请随意选购!");
        //向顾客展示水果
        showGooods(goods);
        //顾客购买水果
        People p1=new People();
        HashMap<Goods, Integer> wantgood=p1.buyGoods(goods);
        //结算
        count(p1,wantgood);
        System.out.println("谢谢光临!欢迎下次再来!");



    }
    //方法：展示水果
    public  static  void showGooods (Goods[] goods) {
        System.out.println("水果编号\t水果名称\t水果价格\t水果库存\t");
        for (int i=0;i<goods.length;i++){
            System.out.println(goods[i].getId()+"\t\t"+goods[i].getName()+"\t\t"+goods[i].getPrice()+"\t\t"+goods[i].getShortage());
        }
    }
    //方法：结算价钱
    public static void count(People p, HashMap<Goods, Integer> goodsList) {
        double total=0;
        Set<Goods> set=goodsList.keySet();
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        System.out.println("请输入会员名字:");
        p.setName(sc.next());
        Random random=new Random();
        int orderNumber=random.nextInt();
        System.out.println("订单编号:"+Math.abs(orderNumber)+"\n购买时间"+ LocalDateTime.now()+"\n会员名:"+p.getName());
        for (Goods goods:set){
            int number=goodsList.get(goods);
            total+=goods.getPrice()*number;
            System.out.println("水果名字:"+goods.getName()+"\n单价:"+goods.getPrice()+"\n总价:"+total);
        }
    }
}